import tkinter as tk
import random
import time

def create_tip_window(main_window, tips, bg_colors):
    """
    创建提示窗口
    
    Args:
        main_window: 主窗口对象
        tips: 提示文本列表
        bg_colors: 背景颜色列表
    
    Returns:
        创建的窗口对象
    """
    window_width = 300
    window_height = 90
    # 确保窗口不会完全超出屏幕范围
    x = random.randint(-30, 1500)
    y = random.randint(-20, 980)
    
    window = tk.Toplevel(main_window)
    window.title('温馨提示')
    window.geometry(f"{window_width}x{window_height}+{x}+{y}")
    window.attributes('-topmost', True)
    
    # 随机选择提示文本和背景颜色
    tip = random.choice(tips)
    bg = random.choice(bg_colors)
    
    tk.Label(
        window,
        text=tip,
        bg=bg,
        font=('微软雅黑', 16),
        width=36,
        height=3
    ).pack()
    
    return window

def close_windows_one_by_one(all_windows, index=0, delay=10):
    """
    逐个关闭窗口
    
    Args:
        all_windows: 所有窗口对象的列表
        index: 当前要关闭的窗口索引
        delay: 下次关闭的延迟时间（毫秒）
    """
    if index < len(all_windows):
        window = all_windows[index]
        if window and window.winfo_exists():
            try:
                window.destroy()
            except Exception:
                pass  # 忽略可能的错误
        
        # 安全地获取主窗口并设置延迟调用
        if all_windows:
            all_windows[0].master.after(delay, close_windows_one_by_one, all_windows, index + 1, delay)
    else:
        # 所有窗口关闭后显示最终窗口
        if all_windows:
            create_final_window(all_windows[0].master)

def create_final_window(main_window):
    """
    创建最终的提示窗口
    
    Args:
        main_window: 主窗口对象
    """
    final_width = 300
    final_height = 90
    
    # 计算居中位置
    screen_width = main_window.winfo_screenwidth()
    screen_height = main_window.winfo_screenheight()
    x = (screen_width - final_width) // 2
    y = (screen_height - final_height) // 2
    
    final_window = tk.Toplevel(main_window)
    final_window.title('温馨提示')
    final_window.geometry(f"{final_width}x{final_height}+{x}+{y}")
    final_window.attributes('-topmost', True)
    
    tk.Label(
        final_window,
        text='我想你了石夏丽',
        bg='lightpink',
        font=('微软雅黑', 18, 'bold'),
        width=30,
        height=3
    ).pack()

def main():
    """
    主函数，创建并运行应用程序
    """
    main_window = tk.Tk()
    main_window.withdraw()  # 隐藏主窗口
    
    # 提示文本列表
    tips = [
        '多喝水哦~', '保持微笑呀', '每天都要元气满满',
        '记得吃水果', '保持好心情', '好好爱自己', '我想你了',
        '梦想成真', '期待下一次见面', '顺顺利利', '早点休息',
        '愿所有烦恼都消失', '别熬夜', '今天过得开心嘛', '天冷了，多穿衣服'
    ]
    
    # 背景颜色列表
    bg_colors = [
        'lightpink', 'skyblue', 'lightgreen', 'lavender',
        'lightyellow', 'plum', 'coral', 'bisque', 'aquamarine',
        'mistyrose', 'honeydew', 'lavenderblush', 'oldlace'
    ]
    
    all_windows = []
    # 创建多个提示窗口
    for _ in range(200):
        window = create_tip_window(main_window, tips, bg_colors)
        all_windows.append(window)
        main_window.update()
        time.sleep(0.01)
    
    # 延迟后开始关闭窗口
    main_window.after(2000, close_windows_one_by_one, all_windows)
    
    # 运行主循环
    main_window.mainloop()

if __name__ == "__main__":
    main()